<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 先利用函数封装传参
    function random(min, max) {
      // 再用return把得到的值给丢出去
      return Math.floor(Math.random() * (max - min + 1)) + min
    }
    // 设置一个值为min = 0，max = 20
    let num = random(0, 20)

    let flay = true
    for (let i = 0; i < 8; i++) {
      let uname = +prompt(`请输入一个数字`)
      if (uname < num) {
        alert(`您猜的数字大了`)
      }
      if (uname > num) {
        alert(`您猜的数字小了`)
      }
      if (uname === num) {
        alert(`恭喜你答对了`)
      }

    }
    if (flay) {
      alert(`太笨了，这都猜不到！O(∩_∩)O`)
    }
  </script>
</body>

</html>